﻿using System.IO;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using Avalonia.ReactiveUI;
using Avalonia.Threading;
using MilkTeaMachine.OfflineClient.ViewModels;
using ReactiveUI;

namespace MilkTeaMachine.OfflineClient.Views;

public partial class WeightingCalibrationUserControl : ReactiveUserControl<WeightingCalibrationViewModel>
{
    public WeightingCalibrationUserControl()
    {
        AvaloniaXamlLoader.Load(this);
        this.WhenActivated(_ => { });
    }

    private void Button1_OnClick(object? sender, RoutedEventArgs e)
    {
        var image = this.FindControl<Image>("Image1");
        if (image != null)
            Dispatcher.UIThread.InvokeAsync(() =>
                image.Source = new Bitmap(Path.Combine(App.SharedResourceRootPath, "greenLight.png")));
    }

    private void Button2_OnClick(object? sender, RoutedEventArgs e)
    {
        var image = this.FindControl<Image>("Image2");
        if (image != null)
            Dispatcher.UIThread.InvokeAsync(() =>
                image.Source = new Bitmap(Path.Combine(App.SharedResourceRootPath, "greenLight.png")));
    }

    private void Button3_OnClick(object? sender, RoutedEventArgs e)
    {
        var image = this.FindControl<Image>("Image3");
        if (image != null)
            Dispatcher.UIThread.InvokeAsync(() =>
                image.Source = new Bitmap(Path.Combine(App.SharedResourceRootPath, "greenLight.png")));
    }

    private void Button4_OnClick(object? sender, RoutedEventArgs e)
    {
        var image = this.FindControl<Image>("Image4");
        if (image != null)
            Dispatcher.UIThread.InvokeAsync(() =>
                image.Source = new Bitmap(Path.Combine(App.SharedResourceRootPath, "greenLight.png")));
    }

    private void Button5_OnClick(object? sender, RoutedEventArgs e)
    {
        var image = this.FindControl<Image>("Image5");
        if (image != null)
            Dispatcher.UIThread.InvokeAsync(() =>
                image.Source = new Bitmap(Path.Combine(App.SharedResourceRootPath, "greenLight.png")));
    }
}